package com.zzyl.nursing.controller;

import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.nursing.domain.Bed;
import com.zzyl.nursing.service.IBedService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 床位Controller
 *
 * @author ruoyi
 * @date 2025-10-20
 */
@RestController
@RequestMapping("/nursing/bed" )
@Tag(name = "床位相关接口" )
public class BedController extends BaseController {
    @Autowired
    private IBedService bedService;

    /**
     * 查询床位列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:bed:list')" )
    @GetMapping("/list" )
    @Operation(summary = "查询床位列表" )
    public TableDataInfo list(Bed bed) {
        startPage();
        List<Bed> list = bedService.selectBedList(bed);
        return getDataTable(list);
    }

    /**
     * 导出床位列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:bed:export')" )
    @Log(title = "床位" , businessType = BusinessType.EXPORT)
    @Operation(summary = "导出床位列表" )
    @PostMapping("/export" )
    public void export(HttpServletResponse response, Bed bed) {
        List<Bed> list = bedService.selectBedList(bed);
        ExcelUtil<Bed> util = new ExcelUtil<Bed>(Bed.class);
        util.exportExcel(response, list, "床位数据" );
    }

    /**
     * 获取床位详细信息
     */
    @PreAuthorize("@ss.hasPermi('nursing:bed:query')" )
    @GetMapping("/{id}" )
    @Operation(summary = "获取床位详细信息" )
    public R<Bed> getInfo(@Schema(title = "床位ID" )
                          @PathVariable("id" ) Long id) {
        return R.ok(bedService.selectBedById(id));
    }

    /**
     * 新增床位
     */
    @PreAuthorize("@ss.hasPermi('nursing:bed:add')" )
    @Log(title = "床位" , businessType = BusinessType.INSERT)
    @PostMapping
    @Operation(summary = "新增床位" )
    public AjaxResult add(@Schema(title = "床位实体" ) @RequestBody Bed bed) {
        return toAjax(bedService.insertBed(bed));
    }

    /**
     * 修改床位
     */
    @PreAuthorize("@ss.hasPermi('nursing:bed:edit')" )
    @Log(title = "床位" , businessType = BusinessType.UPDATE)
    @PutMapping
    @Operation(summary = "修改床位" )
    public AjaxResult edit(@Schema(title = "床位实体" ) @RequestBody Bed bed) {
        return toAjax(bedService.updateBed(bed));
    }

    /**
     * 删除床位
     */
    @PreAuthorize("@ss.hasPermi('nursing:bed:remove')" )
    @Log(title = "床位" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    @Operation(summary = "删除床位" )
    public AjaxResult remove(@Schema(title = "床位ID数组" ) @PathVariable Long[] ids) {
        return toAjax(bedService.deleteBedByIds(ids));
    }
}
